﻿var redirectURL = "http://www.mapfre-assistance.com.cn/", resellerId = "1", affiliateId = "1234567890", errorMessage; 
function setSelectListToValue(f, e) {var d, c, a, b = setSelectListToValue.arguments; if ((obj = document.getElementById(b[1])) != null) { a = b[0]; for (d = 0; d < obj.length; d++) { if (obj.options[d].value == a) { c = d } } obj.selectedIndex = c } 
window.onload = function () { setUpPage(f) } }
function addDays(c, e) { var b = new Date(c.getTime() + e * 24 * 60 * 60 * 1000); var a = new Date(b.getFullYear(), b.getMonth(), b.getDate()); return a }
function getSelectValue(a) { return document.getElementById(a).options[document.getElementById(a).selectedIndex].value }
function isDate(b) { var f = /^(\d{2})(\/)(\d{2})(\/)(\d{4})$/, e = b.match(f), d, a, g, c; if (e === null) { errorMessage = "Please enter dates in the format dd/mm/yyyy."; return false } a = e[1]; g = e[3]; c = e[5]; if (g < 1 || g > 12) { errorMessage = "Month must be between 01 and 12."; return false } if (a < 1 || a > 31) { errorMessage = "Day must be between 1 and 31."; return false } if ((g === 4 || g === 6 || g === 9 || g === 11) && a === 31) { switch (g) { case 4: errorMessage = "April doesn`t have 31 days!"; break; case 6: errorMessage = "June doesn`t have 31 days!"; break; case 9: errorMessage = "September doesn`t have 31 days!"; break; case 11: errorMessage = "November doesn`t have 31 days!"; break } return false } if (g === 2) { d = (c % 4 === 0 && (c % 100 !== 0 || c % 400 === 0)); if (a > 29 || (a === 29 && !d)) { errorMessage = "February " + c + " doesn`t have " + a + " days!"; return false } } return true }
function changeDateSlashesToHyphensForUrl(b) { var a = b.split("/"); return a[0] + "-" + a[1] + "-" + a[2] }
//function getDestinationOption(a) { switch (a) { case 1: return "Europe (exc. Algeria, Israel, Jordan, Libya & Lebanon)"; case 3: return "Australia and New Zealand"; case 2: return "Worldwide (exc. USA & Canada)"; case 4: return "Worldwide (inc. USA & Canada)"; case 0: return "Your home area, England, Scotland, Wales or N. Ireland" } } 
//function addDestinationOptions(b) { for (var a = 0; a < b.length; a++) { document.getElementById("ddDestination").options[a] = new Option(getDestinationOption(b[a]), b[a], (b[a] === 1), false) } }
//function populateDestinations(a) { document.getElementById("ddDestination").options.length = 0; switch (a) { case "4": addDestinationOptions([1, 3, 2, 4]); break; case "1": addDestinationOptions([1, 4]); break; default: addDestinationOptions([1, 3, 2, 4, 0]); break } }
function addLeadingZero(a) { if (a.toString().length < 2) { return "0" + a } return a }
function formatDate(b) { var a = b.getDate() + 1, c = b.getMonth() + 1, d = b.getFullYear(); return d + "/" + addLeadingZero(c) + "/" + addLeadingZero(a) }
function populateCoverDates(b) { var c = document.getElementById("txtCoverEndDate"), a = new Date(); document.getElementById("txtCoverStartDate").value = formatDate(a); switch (b) { case "4": case "3": a = addDays(a, 30); break; case "1": a.setFullYear(a.getFullYear() + 1); a = addDays(a, -1); break; default: a = addDays(a, 2); break } c.value = formatDate(a) }
function onNoOfTravellersChanged() { var c = getSelectValue("ddlNoOfTravellers"), b, a; if (c < 1) { c = 1 } if (c > 10) { c = 10 } for (b = 1; b <= 10; b++) { a = document.getElementById("div_travellerAge_" + b); a.style.display = (b <= c) ? "block" : "none" } }
function formatAgesToCommaDelimitedString() { var c = document.getElementById("tb_travellerAge_1").value, b, a; for (b = 2; b <= getSelectValue("ddlNoOfTravellers"); b++) { a = document.getElementById("tb_travellerAge_" + b).value; if (a != "") { c += "," + a } } return c }
function getAgeRangesByPolicyType(a) { var c = [0, 75], b = getSelectValue("ddPolicyType"); if (a) { c[0] = 18 } switch (b) { case "5": c[0] = 66; break; case "4": c[1] = 65; break; case "3": c[1] = 65; break } return c }
function validateTextBox(d, a, b) { var c = parseInt(a.value, 10); if (d.style.display != "block") { return true } if (!isNaN(c)) { if (c >= b[0]) { errorMessage = (c > 75) ? "Sorry, we can't give you a quote online if any traveller in your group is aged over 75. Please call us on the number above and we can arrange cover for you." : "All additional travellers must be aged " + b[1] + " or under."; return c <= b[1] } else { errorMessage = "All additional travellers must be aged " + b[0] + " or over." } } else { errorMessage = "Please enter all traveller ages as a valid number." } return false }
function validateAdditionalTravellerAges() { var b = getAgeRangesByPolicyType(false); for (var a = 2; a <= 10; a++) { if (!validateTextBox(document.getElementById("div_travellerAge_" + a), document.getElementById("tb_travellerAge_" + a), b)) { return false } } return true }
function validateMainTravellerAge() { var a = getAgeRangesByPolicyType(true), b = parseInt(document.getElementById("tb_travellerAge_1").value, 10); if (!isNaN(b)) { if (b >= a[0]) { errorMessage = (b > 75) ? "Sorry, we can't give you a quote online if any traveller in your group is aged over 75. Please call us on the number above and we can arrange cover for you." : "The main traveller must be aged " + a[1] + " or under."; return b <= a[1] } errorMessage = "The main traveller must be aged " + a[0] + " or over." } else { errorMessage = "Please enter all traveller ages as a valid number." } return false }
function getDateFromInput(a) { var b = a.split("/"); var c = new Date(b[2], b[1] - 1, b[0]); return c }
function validateCoverDates() { if (!isDate(document.getElementById("txtCoverStartDate").value)) { return false } if (!isDate(document.getElementById("txtCoverEndDate").value)) { return false } var e = new Date(), b, d = new Date(), g = getDateFromInput(document.getElementById("txtCoverStartDate").value), a = getDateFromInput(document.getElementById("txtCoverEndDate").value), c, f; b = new Date(e.getFullYear(), e.getMonth(), e.getDate()); d.setFullYear(d.getFullYear() + 1); if (g < b) { errorMessage = "Your cover start date cannot be before today."; return false } if (g > d) { errorMessage = "Your cover start date cannot be more than one year in advance."; return false } if (g > a) { errorMessage = "Your cover start date cannot be after your cover end date"; return false } if (a < b) { errorMessage = "Your cover end date cannot be before today."; return false } switch (getSelectValue("ddPolicyType")) { case "3": case "4": c = 30; f = 539; break; case "5": c = 2; f = 30; break; default: c = 0; f = 364; break } if (getSelectValue("ddPolicyType") != "1") { if (addDays(g, c) > addDays(a, 0)) { errorMessage = "The minimum length of cover for this policy type is " + (c + 1) + " days"; return false } else { if (addDays(g, f) < addDays(a, 0)) { errorMessage = "The maximum length of cover for this policy type is " + (f + 1) + " days"; return false } } } return true }
function validatePromoCode() { var c = /^[a-zA-Z0-9-\s]+$/, a = document.getElementById("TextBoxPromoCode").value, b = a.match(c); if (b === null && a != "") { errorMessage = "Please enter a valid promo code."; return false } return true }
function successfullyValidated() { return true; if (!validateMainTravellerAge()) { return false } if (!validateAdditionalTravellerAges()) { return false } if (!validateCoverDates()) { return false } return true }
function showHideAmtDateAfterTodayWarning() { var c = (getSelectValue("ddPolicyType") == "1"), b = new Date(), a, d = getDateFromInput(document.getElementById("txtCoverStartDate").value); a = new Date(b.getFullYear(), b.getMonth(), b.getDate()); document.getElementById("amtDateAfterTodayWarning").style.display = (c && d > a) ? "block" : "none" }
function showHideEndDateAndPopulateCoverDates(a) { var b = (a == "1"), d = "url(/resources/images/quickquote/QQ_header2amt.png)", c = "url(/resources/images/quickquote/QQ_header2.png)"; document.getElementById("divCoverEndDate").style.display = b ? "none" : "block" }
function setUpPage(a) { showHideEndDateAndPopulateCoverDates(a); populateCoverDates(a); /*populateDestinations(a);*/ showHideAmtDateAfterTodayWarning() }
function onPolicyTypeChange() { setUpPage(getSelectValue("ddPolicyType")) }
function init() { setSelectListToValue("0", "ddPolicyType"); setUpPage("0"); onNoOfTravellersChanged() }
function btnNext_Click() {return true; if (successfullyValidated()) { var f = getSelectValue("ddPolicyType"), a = getSelectValue("ddGroupType"), d = getSelectValue("ddDestination"), g = getSelectValue("ddlNoOfTravellers"), b = changeDateSlashesToHyphensForUrl(document.getElementById("txtCoverStartDate").value), e = changeDateSlashesToHyphensForUrl(document.getElementById("txtCoverEndDate").value), c; switch (f) { case "1": c = "AMT/"; break; case "2": c = "WinterSports/"; break; case "3": c = "LongStay/"; break; case "4": c = "Backpackers/"; break; case "5": c = "Over65/"; break; case "6": c = "business/"; break; default: c = ""; break } c += "default.aspx?type=QQ&pt=" + f + "&grpt=" + a + "&dt=" + d + "&jsd=" + b + "&jed=" + e + "&numoft=" + g + "&travs=" + formatAgesToCommaDelimitedString() + "&rs=" + resellerId + "&af=" + affiliateId; document.location.href = redirectURL + c } else { alert(errorMessage) } return false } 
window.onload = function () { init() };